<?php
/**
 * @var View $this
 * @var string $name
 * @var ArrayDataProvider $dataProvider
 */

use yii\data\ArrayDataProvider;
use backend\components\widget\adminLTE\GridView;
use backend\components\helper\EasyHtml;
use backend\modules\log\Log;
use yii\web\View;

$this->params['breadcrumbs'][] = ['label' => '错误日志', 'url' => ['index']];
$this->params['breadcrumbs'][] = $name;


$this->title = '错误日志-'.$name;

?>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title"><?= EasyHtml::encode($name) ?></h3>
                <div class="box-tools pull-right">
                    <?= EasyHtml::iconLink('返回', ['index'], [
                        'icon' => 'arrow-left',
                        'class' => 'btn btn-default',
                    ]) ?>
                </div>
            </div>
            <div class="box-tools form-inline">
                <div class="box-body">
                    <?= GridView::widget([
                        'dataProvider' => $dataProvider,
                        'columns' => [
                            [
                                'label' => '文件名称',
                                'attribute' => 'fileName',
                                'format' => 'raw',
                                'value' => function (Log $log) {
                                    return pathinfo($log->fileName, PATHINFO_BASENAME);
                                },
                            ],
                            [
                                'label' => '统计',
                                'attribute' => 'counts',
                                'format' => 'raw',
                                'value' => function (Log $log) {
                                    return $this->render('_counts', ['log' => $log]);
                                },
                            ],
                            [
                                'label' => '大小',
                                'attribute' => 'size',
                                'format' => 'shortSize',
                                'headerOptions' => ['class' => 'sort-ordinal'],
                            ],
                            [
                                'label' => '更新时间',
                                'attribute' => 'updatedAt',
                                'format' => 'relativeTime',
                                'headerOptions' => ['class' => 'sort-numerical'],
                            ],
                            [
                                'header' => '操作',
                                'class' => '\yii\grid\ActionColumn',
                                'template' => '{view} {delete}',
                                'urlCreator' => function ($action, Log $log) {
                                    return [$action, 'slug' => $log->slug, 'stamp' => $log->stamp];
                                },
                                'buttons' => [
                                    'view' => function ($url) {
                                        return EasyHtml::iconLink('查看', $url, [
                                            'icon' => 'eye',
                                            'class' => 'btn btn-xs btn-default',
                                            'target' => '_blank',
                                        ]);
                                    },
                                    'delete' => function ($url) {
                                        return EasyHtml::iconLink('删除', $url, [
                                            'icon' => 'trash-o',
                                            'class' => 'btn btn-xs btn-danger',
                                            'data' => [
                                                'method' => 'post',
                                                'confirm' => '确定要执行此操作吗?'
                                            ],
                                        ]);
                                    },
                                ],
                            ],
                        ],
                    ]) ?>
                </div>
            </div>
        </div>
    </div>
</div>
